package com.java110.mall.cart.cmd.storeOrder;

import com.alibaba.fastjson.JSONObject;
import com.java110.core.annotation.Java110Cmd;
import com.java110.core.context.ICmdDataFlowContext;
import com.java110.core.event.cmd.Cmd;
import com.java110.core.event.cmd.CmdEvent;
import com.java110.dto.storeOrder.ResultComputeStoreOrderPriceDto;
import com.java110.intf.cart.IUnifiedOrderInnerServiceSMO;
import com.java110.utils.exception.CmdException;
import com.java110.utils.util.Assert;
import com.java110.vo.ResultVo;
import org.springframework.beans.factory.annotation.Autowired;

/**
 * 拼团订单价格计算功能
 */
@Java110Cmd(serviceCode = "storeOrder.computeGroupProductPrice")
public class ComputeGroupProductPriceCmd extends Cmd {

    @Autowired
    private IUnifiedOrderInnerServiceSMO unifiedOrderInnerServiceSMOImpl;



    @Override
    public void validate(CmdEvent event, ICmdDataFlowContext cmdDataFlowContext, JSONObject reqJson) throws CmdException {
        Assert.hasKeyAndValue(reqJson, "shopId", "未包含商铺信息");
        Assert.hasKeyAndValue(reqJson, "groupId", "未包含拼团ID");

    }

    @Override
    public void doCmd(CmdEvent event, ICmdDataFlowContext cmdDataFlowContext, JSONObject reqJson) throws CmdException {

       ResultComputeStoreOrderPriceDto resultComputeStoreOrderPriceDto = unifiedOrderInnerServiceSMOImpl.computeGroupProductPrice(reqJson);
        cmdDataFlowContext.setResponseEntity(ResultVo.createResponseEntity(resultComputeStoreOrderPriceDto));
    }
}
